<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>应聘人员管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../css/main.css" media="all">
</head>


<body>
<!--主体内容-->
<div class="layui-fluid" style="height: 590px">
    <div class="layui-row">
        <table id="tableyp" lay-filter="ypfilter" style="text-align: center"></table>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">谢拒</a>
        </script>
        <script type="text/html" id="leavingmessage">
            <a class="layui-btn layui-btn-xs" lay-event="msag">消息</a>
        </script>
        <script type="text/html" id="lookover">
            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="look">查看</a>
        </script>
    </div>
</div>

<script src="../../libs/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['form', 'layer', 'jquery', 'table', 'okUtils', 'okLayer'], function () {
        let layer = layui.layer;
        let table = layui.table;
        let okUtils = layui.okUtils;
        let $ = layui.jquery;
        let okLayer = layui.okLayer;

        //获取上一个页面传来的参数
        let jobid = window.location.href.split("?")[1].split("=")[1];
        // 获取contentText
        const ctx = function () {
            let pathName = document.location.pathname;
            let index = pathName.substr(1).indexOf("/");
            let result = pathName.substr(0, index + 1);
            return result;
        }();
        //渲染
        window.ins2 = table.render({
            elem: '#tableyp'
            , title: '岗位招聘数据'
            , url: ctx + '/ygssecs/getRecordListbyjobid?jobid=' + jobid
            , size: 'lg'
            , autoSort: false
            , loading: true
            , limit: 7
            , skin: 'nob'
            , page: {
                limit: 7
                , layout: ['prev', 'page', 'next', 'count', 'skip']
            }
            , response: {
                statusCode: 200
            }
            , request: {
                pageName: 'pageNum'
                , limitName: 'pageSize'
            }
            , cols: [[
                {
                    field: 'jobname', title: '岗位名称', templet: function (d) {
                        return d.job ? d.job.jobname || '' : ''
                    }, fixed: 'left', unresize: true, align: 'center', width: 130
                }
                , {field: 'recordid', title: '招聘序号', unresize: true, align: 'center', width: 90, hide: true}
                , {
                    field: 'stuid', title: '学生学号', templet: function (d) {
                        return d.student ? d.student.stuid || '' : ''
                    }, unresize: true, align: 'center', width: 130
                }
                , {
                    field: 'realname', title: '学生姓名', templet: function (d) {
                        return d.student ? d.student.realname || '' : ''
                    }, hide: 0, align: 'center', unresize: true
                }
                , {
                    field: 'sex', title: '学生性别', templet: function (d) {
                        return d.student ? d.student.sex || '' : ''
                    }, unresize: true, align: 'center'
                }
                , {
                    field: 'dateofbirth', title: '学生年龄', templet: function (da) {
                        var strBirthday = da.student ? da.student.dateofbirth || '' : '';
                        var returnAge
                        var strBirthdayArr = strBirthday.split('-')
                        var birthYear = strBirthdayArr[0]
                        var birthMonth = strBirthdayArr[1]
                        var birthDay = strBirthdayArr[2]
                        var d = new Date()
                        var nowYear = d.getFullYear()
                        var nowMonth = d.getMonth() + 1
                        var nowDay = d.getDate()
                        if (nowYear == birthYear) {
                            returnAge = 0 //同年 则为0岁
                        } else {
                            var ageDiff = nowYear - birthYear //年之差
                            if (ageDiff > 0) {
                                if (nowMonth == birthMonth) {
                                    var dayDiff = nowDay - birthDay //日之差
                                    if (dayDiff < 0) {
                                        returnAge = ageDiff - 1
                                    } else {
                                        returnAge = ageDiff
                                    }
                                } else {
                                    var monthDiff = nowMonth - birthMonth //月之差
                                    if (monthDiff < 0) {
                                        returnAge = ageDiff - 1
                                    } else {
                                        returnAge = ageDiff
                                    }
                                }
                            } else {
                                returnAge = -1 //返回-1 表示出生日期输入错误 晚于今天
                            }
                        }
                        return returnAge //返回周岁年龄
                    }, unresize: true, align: 'center'
                }
                , {
                    field: 'education', title: '学历', templet: function (d) {
                        return d.student ? d.student.education || '' : ''
                    }, unresize: true, align: 'center'
                }
                , {
                    field: 'professionname', title: '所学专业', templet: function (d) {
                        return d.student ? d.student.clzaa.profession.professionname || '' : ''
                    }, unresize: true, align: 'center', width: 180
                }
                , {field: 'lookover', title: '详细信息', templet: '#lookover', unresize: true, align: 'center'}
                , {field: 'leavingmessage', title: '学生留言', templet: '#leavingmessage', unresize: true, align: 'center'}
                , {fixed: 'right', title: '操作', templet: '#barDemo', unresize: true, align: 'center'}
            ]]
        });

        function delinfo(recordid) {
            okUtils.ajax("/ygssecs/deleteRecordbyrecordid?recordid=" + recordid, "post", null, true).done(function (res) {
                location.reload()
            })
        }

        function lookupstuinfo(stuid) {
            okLayer.open("查看学生信息", "lookupStuinfo.html?stuid=" + stuid, "90%", "90%")
        }


        //监听行工具事件
        table.on('tool(ypfilter)', function (obj) {
            let tabledata = obj.data;
            switch (obj.event) {
                case "look":
                    lookupstuinfo(tabledata.student.stuid);
                    break;
                case "del":
                    layer.confirm("您确定要拒绝这位应聘者吗？", function () {
                        delinfo(tabledata.recordid)
                    })
                    break;
                case "msag":
                    layer.open({
                        type: 2,
                        title: '消息',
                        shadeClose: true,
                        shade: 0.4,
                        area: ['900px', '600px'],
                        content: 'enterpriseChatPage.html?recordid=' + tabledata.recordid + "&stuid=" + tabledata.student.stuid
                    });
                    break;
            }

        });
    });
</script>

</body>
</html>